package cz.apnetis.fitweb.client;

import java.util.Date;

import cz.apnetis.fitweb.shared.DayFoodKind;
import cz.apnetis.gwt.client.IntegerStringConverter;
import cz.apnetis.gwt.client.ShortDateStringConverter;
import cz.apnetis.gwt.client.StringConverter;
import cz.apnetis.gwt.client.StringToStringConverter;

/** This class is used for initializing everithing in application
 * @author Lukas "benzin" Benda <a href="mailto:luk.benda@gmail.com">luk.benda@gmail.com</a>
 */
public class InitializeEverithinig {

  public static boolean dayFoodKindInitialized = false;
  public static boolean foodFieldsInitialized = false;
  public static boolean stringConverterInitialized = false;

  /** This method is called by entry point */
  public final static void initializeEverithink() {
    initDayFoodKind();
    initFoodFields();
    initStringConverter();
  }

  public final static void initDayFoodKind() {
    if (!dayFoodKindInitialized) {
      DayFoodKind.BREAKFAST.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_BREAKFAST());
      DayFoodKind.SNACK_MORNING.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_SNACK_MORNING());
      DayFoodKind.LUNCH.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_LUNCH());
      DayFoodKind.SNACK_AFTERNOON.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_SNACK_AFTERNOON());
      DayFoodKind.DINER.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_DINER());
      DayFoodKind.SUPER.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_SUPER());
      DayFoodKind.PARTY.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_PARTY());
      DayFoodKind.SUPLEMENT.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_SUPER());
      DayFoodKind.EXTRA.seI18nString(FitwebMessages.INSTANCE.dayFoodKind_EXTRA());
      dayFoodKindInitialized = true;
    }
  }

  public final static void initFoodFields() {
    if (!foodFieldsInitialized) {
      FoodFields.DATE.setI18nString(FitwebMessages.INSTANCE.date());
      FoodFields.TIME.setI18nString(FitwebMessages.INSTANCE.time());
      FoodFields.NAME.setI18nString(FitwebMessages.INSTANCE.name());
      FoodFields.KIND.setI18nString(FitwebMessages.INSTANCE.kind());
      FoodFields.INGREDIENT.setI18nString(FitwebMessages.INSTANCE.ingredientOverview());
      FoodFields.KJ.setI18nString(FitwebMessages.INSTANCE.kj());
      FoodFields.KCAL.setI18nString(FitwebMessages.INSTANCE.kcal());
      foodFieldsInitialized = true;
    }
  }

  public final static void initStringConverter() {
    if (!stringConverterInitialized) {
      StringConverter.DEFAULT_CONVERTERS.put(String.class, new StringToStringConverter());
      StringConverter.DEFAULT_CONVERTERS.put(Integer.class, new IntegerStringConverter());
      StringConverter.DEFAULT_CONVERTERS.put(Date.class, new ShortDateStringConverter());
      stringConverterInitialized = true;
    }
  }
}
